var _echarts = require("../charts/echarts"), echarts = _interopRequireWildcard(_echarts);

function _interopRequireWildcard(t) {
    if (t && t.__esModule) return t;
    var a = {};
    if (null != t) for (var e in t) Object.prototype.hasOwnProperty.call(t, e) && (a[e] = t[e]);
    return a.default = t, a;
}

var app = getApp();

Page({
    data: {
        navH: app.globalData.navHeight,
        showBuy: !1,
        goods: !1,
        nogoods: !1
    },
    navBack: function() {
        wx.navigateBack();
    },
    onLoad: function(t) {
        var a;
        void 0 !== t.content ? (a = this, app.util.request({
            url: "entry/wxapp/Setting",
            data: {
                name: "phis_share_pic,phis_share_title,share_title,share_pic"
            },
            showLoading: !1,
            success: function(t) {
                t = t.data.data, a.setData(t);
            }
        }), a.setData({
            content: decodeURIComponent(t.content)
        }, function() {
            a.disGoods();
        })) : wx.navigateBack();
    },
    toGoodsPage: function(t) {
        console.log(t);
        var a = t.currentTarget.dataset.goods_id, e = "&source=" + t.currentTarget.dataset.source;
        void 0 !== t.currentTarget.dataset.goods_url && (e += "&goods_url=" + t.currentTarget.dataset.goods_url), 
        wx.navigateTo({
            url: "../goods/goods?goods_id=" + a + e
        });
    },
    disGoods: function() {
        var a = this;
        wx.showLoading({
            title: "查询中",
            mask: !0
        }), app.util.request({
            url: "entry/wxapp/getDisGoods",
            data: {
                content: a.data.content
            },
            showLoading: !1,
            success: function(t) {
                "ok" == t.data.message ? a.setData({
                    goods: t.data.data,
                    showBuy: !0
                }, function() {
                    a.getHistoryPrice();
                }) : a.getHistoryPricebyUrl();
            }
        });
    },
    getHistoryPricebyUrl: function() {
        var d = this;
        app.util.request({
            url: "entry/wxapp/getHistoryPrice",
            data: {
                url: d.data.content
            },
            showLoading: !1,
            success: function(t) {
                if ("no-goods" != t.data.message) if (d.setData({
                    goods: t.data.data.goods
                }), "[]" != t.data.data.hisp) {
                    var a, e = JSON.parse(t.data.data.hisp), o = new app.util.date(), s = {
                        x: [],
                        y: [],
                        z: [],
                        h: []
                    }, n = 0;
                    for (a in e) for (var i in e[a]) 0 == i && (s.x.push(o.dateToStr("MM-dd", new Date(e[a][i]))), 
                    s.h.push(o.dateToStr("yyyy年MM月dd日", new Date(e[a][i])))), 1 == i && ((0 == a || e[a][i] < n) && (n = e[a][i]), 
                    s.y.push(e[a][i])), 2 == i && s.z.push(e[a][i]);
                    d.setData({
                        showHisP: !0,
                        hisp_lowest: n
                    });
                    var t = d.selectComponent("#mychart-dom-line"), r = {
                        color: [ "#FF6729" ],
                        grid: {
                            containLabel: !0
                        },
                        tooltip: {
                            show: !0,
                            trigger: "axis",
                            position: [ 10, 5 ],
                            backgroundColor: "rgba(236,108,56, 1)",
                            formatter: function(t) {
                                return t = t[0].dataIndex, s.h[t] + " ￥" + s.y[t] + (s.z[t] ? "\n" + s.z[t] : "");
                            }
                        },
                        xAxis: {
                            type: "category",
                            boundaryGap: !1,
                            data: s.x,
                            splitLine: {
                                lineStyle: {
                                    type: "dashed"
                                }
                            }
                        },
                        yAxis: {
                            x: "center",
                            type: "value",
                            splitLine: {
                                lineStyle: {
                                    type: "dashed"
                                }
                            }
                        },
                        series: [ {
                            name: "历史价格",
                            type: "line",
                            data: s.y
                        } ]
                    };
                    t.init(function(t, a, e) {
                        return e = echarts.init(t, null, {
                            width: a,
                            height: e
                        }), t.setChart(e), e.setOption(r), e;
                    });
                } else d.setData({
                    showHisPempty: !0
                }); else d.setData({
                    nogoods: !0
                });
            },
            complete: function() {
                wx.hideLoading();
            }
        });
    },
    getHistoryPrice: function() {
        var d = this;
        app.util.request({
            url: "entry/wxapp/getHistoryPrice",
            data: {
                goods_id: (4 == d.data.goods.source ? d.data.goods.brandId + "-" : "") + d.data.goods.goods_id,
                source: d.data.goods.source,
                shop_type: d.data.goods.shop_type
            },
            showLoading: !1,
            success: function(t) {
                if ("[]" != t.data.data) {
                    var a, e = JSON.parse(t.data.data), o = new app.util.date(), s = {
                        x: [],
                        y: [],
                        z: [],
                        h: []
                    }, n = 0;
                    for (a in e) for (var i in e[a]) 0 == i && (s.x.push(o.dateToStr("MM-dd", new Date(e[a][i]))), 
                    s.h.push(o.dateToStr("yyyy年MM月dd日", new Date(e[a][i])))), 1 == i && ((0 == a || e[a][i] < n) && (n = e[a][i]), 
                    s.y.push(e[a][i])), 2 == i && s.z.push(e[a][i]);
                    d.setData({
                        showHisP: !0,
                        hisp_lowest: n
                    });
                    var t = d.selectComponent("#mychart-dom-line"), r = {
                        color: [ "#FF6729" ],
                        grid: {
                            containLabel: !0
                        },
                        tooltip: {
                            show: !0,
                            trigger: "axis",
                            position: [ 10, 5 ],
                            backgroundColor: "rgba(236,108,56, 1)",
                            formatter: function(t) {
                                return t = t[0].dataIndex, s.h[t] + " ￥" + s.y[t] + (s.z[t] ? "\n" + s.z[t] : "");
                            }
                        },
                        xAxis: {
                            type: "category",
                            boundaryGap: !1,
                            data: s.x,
                            splitLine: {
                                lineStyle: {
                                    type: "dashed"
                                }
                            }
                        },
                        yAxis: {
                            x: "center",
                            type: "value",
                            splitLine: {
                                lineStyle: {
                                    type: "dashed"
                                }
                            }
                        },
                        series: [ {
                            name: "历史价格",
                            type: "line",
                            data: s.y
                        } ]
                    };
                    t.init(function(t, a, e) {
                        return e = echarts.init(t, null, {
                            width: a,
                            height: e
                        }), t.setChart(e), e.setOption(r), e;
                    });
                } else d.setData({
                    showHisPempty: !0
                });
            },
            complete: function() {
                wx.hideLoading();
            }
        });
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {
        var t = (a = this).data.phis_share_title || a.data.share_title, a = a.data.phis_share_pic || a.data.share_pic;
        return {
            title: t,
            path: "/first_duoduoke/pages/trend/trend" + (void 0 !== app.globalData.userInfo.uid ? "?from_uid=" + app.globalData.userInfo.uid + "&from_act=share" : "?from_act=share"),
            imageUrl: a,
            success: function(t) {
                "shareAppMessage:ok" == t.errMsg ? wx.showToast({
                    title: "分享成功",
                    icon: "success"
                }) : wx.showToast({
                    title: "分享失败",
                    icon: "none"
                });
            },
            fail: function(t) {
                "shareAppMessage:fail cancel" == t.errMsg || t.errMsg, wx.showToast({
                    title: "分享失败",
                    icon: "none"
                });
            }
        };
    }
});